**Housekeeping
clear all
cap log close
log using ${rep_root}/logs/condense_complaints.log, text replace
set more off

use ${rep_root}/data/FOIA/FOIA_unified/complaints

**Drop if missing officer or incident date
keep if !missing(mid)
drop if missing(inc_complaint_dt_1)

**Extract year and month from incident date
gen yr = year(inc_complaint_dt_1) 
gen mo = month(inc_complaint_dt_1)

**Drop complaints from before 1999
drop if yr<1999

**Mark if a complain involved the use of force
gen force = 0
forvalues i = 1/4{
	replace force = 1 if inc_cat_`i'==4
}

**Count complaints and force complaints for each officer/yearmonth
sort mid yr mo
by mid yr mo: gen complaints = _N
by mid yr mo: egen force_complaints = total(force)
by mid yr mo: keep if _n==1

**Create the balance panel of officers and yearmonths
fillin mid yr mo

**If an officer/yearmonth wasn't in the original complaint data, there
**wasn't a complain in that period
replace complaints = 0 if _fillin==1
replace force_complaints = 0 if _fillin==1

**Create Stata yearmonth variable, trim and save
keep mid yr mo complaints force_complaints
gen yearmo = ym(yr, mo)
rename yr complaint_yr
rename mo complaint_mo
save ${rep_root}/data/complaints_panel, replace
clear
log close
